<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.cp.vo.CpInfoDTO" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.tags.PageModel" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>

<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.baas.model.CpAccount" %>
<%@ page import="com.qipay.baas.model.Cp" %>
<%@ page import="com.qipay.baas.model.User" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.math.BigDecimal" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
    <style type="text/css">
        .border{
            border:1px solid red;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">代理商列表</h3>
                        </div>
                        <div class="new-group">
                            <label> 代理商名称：</label>
                            <input type="text" id="txtName" value="<%= request.getParameter("name")!=null?request.getParameter("name"):""%>"/>
                        </div>
                        <div class="new-group">
                            <label>代理商ID：</label>
                            <input type="text" id="txtcpid" value="<%= request.getParameter("cpId")!=null?request.getParameter("cpId"):""%>"/>
                        </div>
                        <div class="new-group">
                            <label> 联系人：</label>
                            <input type="text" id="txtContract" value="<%= request.getParameter("contact")!=null?request.getParameter("contact"):""%>"/>
                        </div>
                        <div class="new-group">
                            <label> 联系人手机：</label>
                            <input type="text" id="txtMobile" value="<%= request.getParameter("m")!=null?request.getParameter("m"):""%>"/>
                       </div>
                    <div class="new-group">
                        <label> 状态：</label>
                                <select id="ddltype">
                                    <option value="-1">全部</option>
                                    <option value="0">禁用</option>
                                    <option value="1">审核中</option>
                                    <option value="2">启用</option>
                                </select>
                    </div>
                                <button type="button" class="button back-green" id="btnSearch" style="font-size: 1rem">查询</button>
                        <!-- /.box-header -->
                        <%
                            CpAccount tongji = (CpAccount) request.getAttribute("totalList");
                        %>
                        <div class="tableContent">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1">
                                <thead>
                                <tr>
                                    <th width="14%">代理商ID</th>
                                    <th width="18%">代理商名称</th>
                                    <%--<th width="6%">法人</th>--%>
                                    <th width="10%">余额</th>
                                    <th width="10%">可提</th>
                                    <th width="10%">垫支</th>
                                    <th width="10%">不可提</th>
                                    <th width="10%">已提金额</th>
                                    <th width="8%">手续费</th>
                                  <!--  <th width="8%">联系人</th>
                                    <th width="13%">联系人手机</th>
                                    <th width="6%">状态</th>
                                    <th width="8%">签约</th>
                                    <th width="10%">加入时间</th> -->
                                    <th width="26%">操作</th>
                                </tr>
                                <tr>
                                    <th width="14%"></th>
                                    <th width="15%"></th>
                                    <%--<th width="8%"></th>--%>
                                    <th width="14%"><span style="color: green;"><%=new BigDecimal(tongji.getBalance()).divide(new BigDecimal(String.valueOf("100")))%></span></th>
                                    <th width="14%"><span style="color: green;"><%= new BigDecimal(tongji.getBalanceAvailable()).divide(new BigDecimal(String.valueOf("100")))%></span></th>
                                    <th width="10%"><span style="color: green;"><%=new BigDecimal(tongji.getBalanceAdvance()).divide(new BigDecimal(String.valueOf("100")))%></span></th>
                                    <th width="12%"><span style="color: green;"><%= new BigDecimal(tongji.getBalanceDisabled()).divide(new BigDecimal(String.valueOf("100")))%></span></th>
                                    <th width="11%"><span style="color: green;"><%= new BigDecimal(tongji.getWidthdrawAmount()).divide(new BigDecimal(String.valueOf("100")))%></span></th>
                                    <th width="9%"><span style="color: green;"><%= new BigDecimal(tongji.getFee()).divide(new BigDecimal(String.valueOf("100")))%></span></th>

                                  <!--  <th width="8%"></th>
                                    <th width="13%"></th>
                                    <th width="6%"></th>
                                    <th width="8%"></th>
                                    <th width="10%"></th>-->
                                    <th width="26%"></th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<CpAccount> articles = (List<CpAccount>) request.getAttribute("lst");
                                    PageModel pager = (PageModel) request.getAttribute("page");
                                    User currentUser = (User) session.getAttribute("user");
                                    UserLevel userLevel = SiteHelper.getUserLevelByLevel(currentUser.getLevel());
                                    String query = pageContext.getRequest().getServletContext().getContextPath() + "/proxy" + pager.getUrl();
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<CpAccount> iter = articles.iterator();
                                        CpAccount user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                %>
                                <tr id="user_<%=user.getCpId()%>">

                                    <td>
                                        <a href="${pageContext.request.contextPath}/proxy/<%= user.getCpId()%>?agent=1" style="color: #00a65a">
                                            <%= user.getCpId()%>
                                        </a>
                                    </td>
                                    <td>
                                            <%= user.getName()%>
                                    </td>
                                    <%--<td>--%>
                                        <%--<%= user.getLegalPerson()%>--%>
                                    <%--</td>--%>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getBalance()/100.0)%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getBalanceAvailable()/100.0)%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getBalanceAdvance()/100.0)%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getBalanceDisabled()/100.0)%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getWidthdrawAmount()/100.0)%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getMoneyFormatAll(user.getFee()/100.0)%>
                                    </td>

                                    <td>
                                        <div class="button-group">
                                        <a href="${pageContext.request.contextPath}/proxy/<%= user.getCpId()%>/child">
                                            <button type="button" class="button back-green" style="font-size: 1rem">旗下商户</button></a>
                                        <a href="${pageContext.request.contextPath}/proxy/<%= user.getCpId()%>/channel">
                                            <button type="button" class="button back-green" style="font-size: 1rem">渠道</button> </a>
                                        <% if (userLevel == UserLevel.ADMIN) {%>
                                        <a name="lnkDelete" s="<%= user.getAccountState()%>"
                                           pk="<%= user.getCpId()%>" href="javascript:;">
                                            <button type="button" class="button back-red" style="font-size: 1rem"><%= user.getAccountState() != null && user.getAccountState() == 2 ? "禁用" : "启用"%></button>
                                        </a>
                                        <a href="${pageContext.request.contextPath}/proxy/<%= user.getCpId()%>?agent=1">
                                            <button type="button" class="button back-green" style="font-size: 1rem">修改</button></a>
                                        <%}%>
                                        <a  name="lnkRemove" href="javascript:;" pk="<%= user.getCpId()%>">
                                            <button type="button" class="button back-red" style="font-size: 1rem">删除</button></a>
                                        </div>

                                        <%--<a  name="lnkShow" href="javascript:;" pk="<%= user.getCpId()%>" pk1="<%=user.getContacts()%>"--%>
                                            <%--pk2="<%=user.getContactsMobile()%>" pk3="<%=cpModel.getAccountState()%>" pk4="<%=user.getCpCreateTime()%>"--%>
                                            <%--pk5="<%=user.getName()%>"pk6="<%=user.getLegalPerson()%>" pk7="<%=cpModel.getContractState()%>">--%>
                                            <%--<button type="button" class="button back-blue" style="font-size: 1rem">详情</button>--%>
                                        <%--</a>--%>

                                    </td>
                                </tr>
                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="12">未找到数据</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <div class="col-sm-10">

                                <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                                    <page:page totalSum="<%= pager.getTotal()%>"
                                               url="<%= query%>"
                                               pageNo="<%= pager.getPage()%>"
                                               pageSize="<%= pager.getPageSize()%>"></page:page>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>

<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>

    $("[name='lnkShow']").click(function () {
        var cpId = $(this).attr("pk");
        var Contect=$(this).attr("pk1");
        var Moblie=$(this).attr("pk2");
        var accountState=$(this).attr("pk3");
        if(accountState==2){
            accountState="启用";
        }else{
            accountState="禁用";
        }
        var cpCreateTime=$(this).attr("pk4");
        var cpName=$(this).attr("pk5");
        var legalperson=$(this).attr("pk6");
        var ContractState=$(this).attr("pk7");
        if(ContractState==1){
            ContractState="已签约";
        }else{
            ContractState="未签约";
        }
        alert("当前代理商ID："+cpId+"\n代理商名称："+cpName+"\n法人："+legalperson+"\n联系人："+Contect+"\n联系人手机:"+Moblie+"\n状态:"+accountState+"\n签约:"+ContractState+"\n创建时间:"+cpCreateTime);
    });


    $(function () {
        var channelState = parseInt("<%= StringUtils.isNotEmpty(request.getParameter("s"))?request.getParameter("s"):-1%>", 10);
        $("#ddltype").val(channelState);
        $("#btnSearch").on("click", function () {
            var name = $.trim($("#txtName").val());
            var cpId = $.trim($("#txtcpid").val());
            var c = $.trim($("#txtContract").val());
            var m = $.trim($("#txtMobile").val());
            var agent = '<%= request.getParameter("agent")!=null&&request.getParameter("agent").endsWith("1")?"&agent=1":""%>'
            var resm = /^0?(13|15|17|18)[0-9]{9}$/;
            if (m != "" && !resm.test(m)) {
                alert("手机号格式不正确。");
                return;
            }
            var s = $("#ddltype").val();
            if (s == null || s == "null") {
                s = -1;
            }
            window.location.href = "${pageContext.request.contextPath}/proxy?name=" + encodeURIComponent(name) + "&cpId=" + encodeURIComponent(cpId) + "&contact=" + encodeURIComponent(c) + "&m=" + encodeURIComponent(m)+agent+ "&s=" + (s == -1 ? "" : s);
        });
        $("[name='lnkDelete']").click(function () {
            var that = $(this);
            var pk = $(this).attr("pk");
            var state = $(this).attr("s");
            var isSuccess = state=="2";
            if (confirm(isSuccess? "确定禁用吗？" : "确定启用吗？")) {
                state = isSuccess?0:200;
                if (pk > 0) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=setcpaccountstate&id=" + pk + "&id2=" + state,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                if (isSuccess) {
                                    $("#trgoods" + pk).removeClass("success");
                                    $("#trgoods" + pk).html("禁用");
                                    $(this).html("启用");
                                    $(this).attr("s","0");
                                }
                                else {
                                    $("#trgoods" + pk).addClass("success");
                                    $("#trgoods" + pk).html("启用");
                                    $(this).html("禁用");
                                    $(this).attr("s","2");
                                }
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }
        });
        $("[name='lnkRemove']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确定删除吗？")) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=delcpbyid&id=" + pk,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                $("#user_" + pk).hide(100);
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });
    })
</script>
</body>
</html>

